<?php
/**
 * Created by PhpStorm.
 * User: 666
 * Date: 2020/4/9
 * Time: 15:42
 */

namespace App\Crontab;


use App\Consts\RedisKey;
use App\Model\BettingLog;
use App\Model\Lottery;
use App\Model\LotteryCategory;
use App\Model\PoolRecord;
use App\Model\RechargeOption;
use App\Model\RevenueStatement;
use App\Model\TaskLog;
use App\Model\User;
use App\Model\UserLoginLog;
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\EasySwoole\ServerManager;
use EasySwoole\EasySwoole\Task\TaskManager;
use EasySwoole\RedisPool\Redis;

class DailyTask extends AbstractCronTask
{

    public static function getRule(): string
    {
        return '59 23 * * *';
    }

    public static function getTaskName(): string
    {
        return  'daily';
    }

    function run(int $taskId, int $workerIndex)
    {



        //定时处理日志
        $date = date('Y-m-d');
        $logFile  = Config::getInstance()->getConf('MAIN_SERVER.SETTING.log_file');
        $document_root  = Config::getInstance()->getConf('MAIN_SERVER.SETTING.document_root');
        if(is_file($logFile)){
            //先备份
            exec("cp -r $logFile  {$document_root}/Log/{$date}.log");
            //再清空
            exec("echo '' > $logFile");

            exec("cp -r $document_root/Log/log_DEBUG.log  {$document_root}/Log/{$date}_DEBUG.log");
            exec("echo '' > $document_root/Log/log_DEBUG.log");

        }

    }

    function onException(\Throwable $throwable, int $taskId, int $workerIndex)
    {
        echo $throwable->getMessage();
    }
}